package com.lms.controller;

import com.alibaba.fastjson.JSON;
import com.lms.entity.Pubbuildbaseinfo;
import com.lms.service.PubbuildbaseinfoService;
import com.lms.vo.DataVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @Description: 公共楼宇基础信息台账后台控制器类
 * @author: L-B-S
 * @Date: 2021/3/12 16:31
 * @modified_By:
 * @Version: 0.0$
 */
@Controller
public class PubbuildbaseinfoController {

    @Autowired
    private PubbuildbaseinfoService pubbuildbaseinfoService;

    @ResponseBody
    @GetMapping(value = "/pbbi/getList")
    public DataVo<Pubbuildbaseinfo> getList(Integer page, Integer limit) {
        return pubbuildbaseinfoService.getList(page, limit);
    }

    @ResponseBody
    @PostMapping(value = "/pbbi/delPbbis")
    public DataVo<Pubbuildbaseinfo> delOnes(@RequestParam(value = "pbbiList") String pbbiList) {
        List<Pubbuildbaseinfo> data = JSON.parseArray(pbbiList, Pubbuildbaseinfo.class);
        return pubbuildbaseinfoService.delPbbis(data);
    }

    @ResponseBody
    @PostMapping(value = "/pbbi/delOne")
    public DataVo<Pubbuildbaseinfo> delOne(@RequestParam(value = "pubBuildBaseInfo") String pubBuildBaseInfo) {
        Pubbuildbaseinfo data = JSON.parseObject(pubBuildBaseInfo, Pubbuildbaseinfo.class);
        return pubbuildbaseinfoService.delOne(data);
    }

    @ResponseBody
    @PostMapping(value = "/pbbi/add")
    public DataVo<Pubbuildbaseinfo> addOne(Pubbuildbaseinfo pubbuildbaseinfo) {
        return pubbuildbaseinfoService.addOne(pubbuildbaseinfo);
    }

    @ResponseBody
    @PostMapping(value = "/pbbi/edit")
    public DataVo<Pubbuildbaseinfo> edit(Pubbuildbaseinfo pubbuildbaseinfo) {
        return pubbuildbaseinfoService.edit(pubbuildbaseinfo);
    }

    @ResponseBody
    @PostMapping(value = "/pbbi/upload")
    public DataVo<Pubbuildbaseinfo> upload(MultipartFile file) {
        return pubbuildbaseinfoService.uploadExcel(file);
    }

    @GetMapping(value = "/pbbi/{url}")
    public String redirect(@PathVariable("url") String url) {
        return "pbbi/" + url;
    }
}
